import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'loginPage',
      component: () => import('@/views/login/LoginPage.vue')
    },
    {
      path: '/home',
      name: 'homeIndex',
      component: () => import('@/views/home/IndexView.vue'),
      children: []
    },
    {
      path: '/about',
      name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/AboutView.vue')
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (from.name === null) {
    // 如果 from.name 是 null，意味着这是一个页面刷新，需要重定向到当前路由
    next(to.path)
  } else {
    // 正常的导航行为
    next()
  }
})

router.beforeResolve(async (to) => {})
export default router
